var t = require("../../utils/util.js"), e = getApp();

e.globalData.url;

Page({
    data: {
        table_active: 0,
        dataList: [],
        length: !1
    },
    onLoad: function(t) {
        1 == wx.getStorageSync("service") ? (this.onComplete(), wx.removeStorageSync("service")) : this.fetchdata([ "1", "2", "3", "4" ]);
    },
    onShow: function() {
        var t = this, e = t.data.table_active;
        0 == e ? t.onConduct() : 1 == e ? t.onComplete() : t.onFailed();
    },
    myorder: function(t) {
        wx.navigateTo({
            url: "order/order"
        });
    },
    onConduct: function(t) {
        this.setData({
            table_active: 0
        }), this.fetchdata([ "1", "2", "3", "4", "7", "8" ]);
    },
    onComplete: function(t) {
        this.setData({
            table_active: 1
        }), this.fetchdata(5);
    },
    onFailed: function(t) {
        this.setData({
            table_active: 2
        }), this.fetchdataAll();
    },
    fetchdata: function(a) {
        var n = this, r = e.globalData.token;
        t.request(e, "wx/cust/getOrderByCustIdAndOrderState", "POST", {
            orderStateList: a,
            token: r
        }, function(e) {
            var a = e.data.length > 0;
            if (n.setData({
                length: a
            }), e.data.length > 0) {
                var r = e.data;
                for (var o in r) r[o].debateAmount = t.convertMath(r[o].debateAmount);
                n.setData({
                    dataList: r
                });
            }
        }, function(t) {});
    },
    fetchdataAll: function() {
        var a = this, n = e.globalData.token;
        t.request(e, "wx/cust/getOrderByCustIdAndOrderState", "POST", {
            token: n
        }, function(e) {
            var n = e.data.length > 0;
            if (a.setData({
                length: n
            }), e.data.length > 0) {
                var r = e.data;
                for (var o in r) r[o].debateAmount = t.convertMath(r[o].debateAmount);
                a.setData({
                    dataList: r
                });
            }
        }, function(t) {});
    },
    orderInfo: function(t) {
        t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "orderInfo/index?relateOrderId=" + t.currentTarget.dataset.relateorderid + "&id=" + t.currentTarget.dataset.id + "&orderSource=" + t.currentTarget.dataset.ordersource
        });
    },
    wxPay: function(a) {
        var n = a.currentTarget.dataset.id;
        n ? t.wxpay(e, n, "/pages/service/index") : wx.showModal({
            title: "错误",
            content: "无法获取用户资金信息",
            showCancel: !1
        });
    },
    toEvaluate: function(t) {
        t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "orderInfo/index?relateOrderId=" + t.currentTarget.dataset.relateorderid + "&id=" + t.currentTarget.dataset.id + "&orderSource=" + t.currentTarget.dataset.ordersource
        });
    },
    goBuy: function(t) {
        wx.navigateTo({
            url: "/pages/service/order-topay/index?id=" + t.currentTarget.dataset.id
        });
    },
    onPullDownRefresh: function() {
        var t = this, e = t.data.table_active;
        0 == e ? t.onConduct() : 1 == e ? t.onComplete() : t.onFailed(), wx.showNavigationBarLoading(), 
        setTimeout(function() {
            wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
        }, 1e3);
    },
    yuyueConfirm: function(a) {
        var n = this, r = a.currentTarget.dataset.relateorderid, o = e.globalData.token;
        t.request(e, "wx/cust/toShop", "POST", {
            token: o,
            bespeakOrderId: r,
            orderId: a.currentTarget.dataset.id
        }, function(t) {
            t.state ? n.onPullDownRefresh() : wx.showToast({
                title: t.message,
                icon: "none"
            });
        }, function(t) {});
    },
    yuyuecancel: function(a) {
        var n = a.currentTarget.dataset.id, r = e.globalData.token, o = this;
        t.request(e, "wx/cust/cancelOneCBO", "POST", {
            token: r,
            orderId: n
        }, function(t) {
            t.state ? (o.onPullDownRefresh(), wx.showToast({
                title: "取消成功",
                icon: "none"
            })) : wx.showToast({
                title: t.message,
                icon: "none"
            });
        }, function(t) {});
    }
});